package com.ying.tests.CCCbasis.Test5ThreadPool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 使用Runnable接口创建线程池
 */
public class Test5RunnablePool {
    public static void main(String[] args) {
        // 创建线程池对象，参数5，代表有5个线程的线程池
        ExecutorService executorService = Executors.newFixedThreadPool(5);
        // 创建Runnable线程任务对象
        TaskRunnable task = new TaskRunnable();
        // 从线程池中获取线程对象
        executorService.submit(task);// 1000个任务
        System.out.println("----------------------------------------------------");
        // 再获取一个线程对象
        executorService.submit(task);// 1000个任务
        // 关闭线程池
        executorService.shutdown();
    }
}
